<?php 
namespace Admin\Controller;

class CollectionController extends AdminController
{
	public function index()
	{
		$name = I('get.name');
		$collect = M('collection');
		if (empty($name)) {
			$count = $collect->count('id');
			$Page = new \Think\Page($count,5);

			$Page->setConfig('first','首页');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('next','下一页');
			$Page->setConfig('last','尾页');
			$show = $Page->show();
			$data = $collect->field('lamp_collection.id,u.name as uname,m.name as mname,lamp_collection.addtime')->join('lamp_user u on u.id=uid')->join('lamp_movie m on m.id=mid')->order('addtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		} else {
			$count = $collect->field('lamp_collection.id')->join('lamp_user u on u.id=uid')->join('lamp_movie m on m.id=mid')->where('m.name like "%'.$name.'%"')->order('addtime desc')->count();
			$Page = new \Think\Page($count,5);

			$Page->setConfig('first','首页');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('next','下一页');
			$Page->setConfig('last','尾页');
			$map['name'] = $name;
            // var_dump($map);
            $Page->parameter=$map;
			$show = $Page->show();
			$data = $collect->field('lamp_collection.id,u.name as uname,m.name as mname,lamp_collection.addtime')->join('lamp_user u on u.id=uid')->join('lamp_movie m on m.id=mid')->where('m.name like "%'.$name.'%"')->order('addtime desc')->select();

		}
		
		$this->assign('page',$show);
		$this->assign('list',$data);
		// var_dump($data);exit;
		$this->display();
	}
	public function del()
	{
		$id = I('get.id');
		if(M('collection')->delete($id) > 0){
			$this->success('恭喜您删除成功');
		}else{
			$this->error('删除失败');
		}


	}
}
































